class Dog {
  // 指定属性的类型
  name: string;
  age: number;
  // 使用构造函数，初始化属性(在对象创建时调用)
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
    console.log(this); // this指向实例对象
  }

  bark() {
    // 挂载在原型上
    console.log("汪汪汪");
  }
}

const dog1 = new Dog("旺财", 2);
const dog2 = new Dog("大黄", 1);
const dog3 = new Dog("哈士奇", 3);
console.log(dog1, dog2, dog3);
dog1.bark();
